package com.base.myproject.server.ratify;

import java.sql.ResultSet;
import java.util.LinkedList;

import com.base.myproject.server.database.PoolMan;

public class RatifyFlow {
	static RatifyFlow ratifyflow = null;
	private RatifyFlow()
	{
		
	}
	synchronized public static RatifyFlow getInstance()
	{
		if(ratifyflow==null)
		{
			ratifyflow = new RatifyFlow();
		}
		Strlink.clear();
		return ratifyflow;
		
	}
	
	static public java.util.LinkedList<String > Strlink = new java.util.LinkedList<String>();

	
	static public void listratifyobj(RatifyObject ro)
	{
		
		if(ro.ll.size()>0)
		{
			for(int i=0;i<ro.ll.size();i++)
			{
				
					((RatifyObject)ro.ll.get(i)).setPath(ro.getPath());
					//((RatifyObject)ro.ll.get(i)).path +="->"+((RatifyObject)ro.ll.get(i)).getTobcode();
				//<img src="/images/star1.gif" alt="一星会员" title="一星会员"/>
					((RatifyObject)ro.ll.get(i)).setPath(((RatifyObject)ro.ll.get(i)).getPath() +"</td><td><img src=\"/images/baseimage/ratify/direction_right.png\" /></td><td>"+((RatifyObject)ro.ll.get(i)).getTobcodeimg()+"</td>");
				listratifyobj((RatifyObject)ro.ll.get(i));
				
			}
		}
		else
		{
			
			Strlink.add(ro.path);
		}
	//System.out.println(ro.tobcode+"--"+ro.path);
		
	}
	
	public String[][] getRatify(String busicode,String bcode)
	{
		String[][] array = new String[0][3];
		LinkedList<RatifyObject> rolink = new LinkedList<RatifyObject>();
		PoolMan pm = new PoolMan();
		String sql = "";
		sql = "select (select bname from bcode where bcode =tobcode) as  tobcode,tostatus,fromstatus from ratify where busicode='"+busicode+"' and '"+bcode+"' like bcode+'%' group by fromstatus,tostatus,tobcode";
		System.out.println(sql);
		ResultSet rs = null;
		try {
			
			rs = pm.executeQuery(sql);
			
		
		while(rs.next())
		{
			rs.getString("tobcode");
			rs.getString("tostatus");
			rs.getString("fromstatus");
			rolink.add(new RatifyObject(rs.getString("tobcode"),rs.getString("tostatus"),rs.getString("fromstatus")));
		}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				pm.close("test");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		for(int i=0;i<rolink.size();i++)
		{
			
			for(int j=0;j<rolink.size();j++)
			{
				if(rolink.get(i).getTostatus().equals(rolink.get(j).getFromstatus()))
				{
//					((ratifyobject)main[i]).add((ratifyobject)main[j]);
					rolink.get(i).add(rolink.get(j));
					//System.out.println("bingo!!"+((ratifyobject)main[i]).name + " + "+((ratifyobject)main[j]).name);
				}
			}
		}
		//rolink.get(0).path = "1001";
		if(rolink.size()>0)
		listratifyobj(rolink.get(0));
		return array;		
	}
	
	public static void main(String[] argv)
	{
//		RatifyFlow r = RatifyFlow.getInstance();
//		r.getRatify("1001");
//		System.out.println(Strlink.get(0));
//		System.out.println(Strlink.get(1));
		
//		String aa = "qwer%";
//		System.out.println(aa.split(",")[0]);
//		if(1==1)
//			return;
		PoolMan pm = new PoolMan();
		try {
			for(int i=0;i<5000;i++)
			{
			pm.Update("insert into ccode (ccode,cname,phone,shortcode) values('1009','牛逼哄哄"+i+"','asd','nbhhh')");
			}
			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			finally
			{
				try {
					pm.close("text");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
	}

}
